import React, {Component} from 'react';
import {Popup, Tab,Button,Group,Field ,NumberPicker,SelectField, TextField,NoticeBar,CheckboxField,Toast  } from 'saltui';
import Number from  '../../room/Number'
import InputText from '../diy/InputText'
import InputChecked from '../diy/InputChecked'
import  Ajax  from '../../../../Common/Ajax';

/**
 *
 */
export default class SettingAdd extends React.Component {
  constructor(props) {


    super(props);
    this.state = {
      prices :[],
      data:{
        id:this.props.id,
        name: this.props.name,
        price: this.props.price,
        people_num: this.props.people_num,
      }
    };
    this.state.buttonName = this.props.buttonName;


  }

  handleTextChange = (value) =>{
    let data = this.state.data;
    data.name = value;
    this.setState({data:data});
  }

  handleSave = () =>{
    Toast.show({
      type: 'loading',
      content: '保存中...',
      autoHide:false
    });

    setTimeout(() => {
      Ajax.post("roomtype/save",this.state.data);
      Toast.hide(() => {
      });

      Toast.show({
        type: 'loading',
        content: '保存成功',
      });

      Popup.hide();
      this.props.onChange(this.props.typeid);
    }, 2000);
  }


  handleOption= (key,value) =>{
    let data = this.state.data;
    data[key] = value;
    this.setState({data:data});
  }


  render() {
    let that = this;
    return <div className="demo-popup-container">     <Group.List >
      <Field label="名字" tip={<div>输入类型名字</div>}>
        <InputText value={this.state.data.name} onChange={this.handleTextChange}  />
      </Field>
      <Field label="价格" tip={<div>请输入此客房类型统一价格</div>}>
        <div>
          <Number value={this.state.data.price} id = 'price' onChange={that.handleOption} />
        </div>
      </Field>

      <Field label="可住人数" tip={<div>请输入可住人数</div>}>
        <div>
          <Number value={this.state.data.people_num} id = 'people_num' onChange={that.handleOption} />
        </div>
      </Field>

      <Field label="设施" tip={<div>请选设施</div>}>
        <div>
          <InputChecked defaultValue={this.props.amenities} id="amenities" onChange={this.handleOption} option={this.props.option.amenities} />
        </div>
      </Field>


      <Field label="税" tip={<div>请选税</div>}>
        <div>
          <InputChecked defaultValue={this.props.tax} id="tax" onChange={this.handleOption} option={this.props.option.tax} />
        </div>
      </Field>

      <Field label="服务费" tip={<div>请选服务费</div>}>
        <div>
          <InputChecked  defaultValue={this.props.tip} id="tip" onChange={this.handleOption} option={this.props.option.tip} />
        </div>
      </Field>

    </Group.List>
      <div className="notice-div">
        <NoticeBar className="noticeMessage" message={"客房设置"} closable={false} type="warning" />
      </div>
      <div className="demo-line">
        <Button type="secondary"  size="small" onClick={this.handleSave} >提交</Button>
        <Button type="secondary"  size="small"  onClick={Popup.hide}  >取消</Button>
      </div></div>
  }
}
